package com.balance.anole.erp.welcome.view;

import java.io.IOException;
import java.net.URL;

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;
import org.osgi.framework.Bundle;

import com.balance.anole.erp.Activator;

public class WelcomeView extends ViewPart {

	public static final String ID = "com.balance.anole.erp.WelcomeView";

	public void createPartControl(Composite parent) {
		//Text text = new Text(parent, SWT.BORDER);
		//text.setText("Welcome use Anole ERP System.");
		/*Browser b = new Browser(parent, SWT.NONE);
//		b.setUrl("..\\28793-header.swf");

		Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
		Path basePath = new Path("com/balance/anole/erp/welcome/view/28793-header.swf");
		URL findURL = FileLocator.find(bundle, basePath, null);
//	    URL url = plugin.getEntry ("/");
//	    URL url = this.getClass().getClassLoader().getResource("/com/balance/anole/erp/welcome/view/28793-header.swf");
	    try {
	    	URL url  = FileLocator.resolve(findURL);
			b.setUrl(url.getFile());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/

		Browser browser = new Browser(parent, SWT.NONE);
		Bundle plugin = Activator.getDefault().getBundle(); // Where Activator is my org.eclipse.core.runtime.Plugin
		IPath relativePagePath = new Path("index.html");
		URL fileInPlugin = FileLocator.find(plugin, relativePagePath, null);
		URL pageUrl;
		try {
			pageUrl = FileLocator.toFileURL(fileInPlugin);
			browser.setUrl(pageUrl.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


		initializeToolBar();
	}

	public void setFocus() {
	}
	private void initializeToolBar() {
		IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
	}

}
